package newcoder_exp.bytedance;

import java.util.*;

import org.junit.Test;
public class Bd3 {
    
    //最大共线点数
    public int maxOnlinePoionts(double[][] poionts) {
        Map<double[], Integer> lines = new HashMap<>();
        int len = poionts.length;
        for (int i = 0; i < len - 1; i++) {
            for (int j = i + 1;  j < len; j++) {
                double a = poionts[j][0] - poionts[i][0], 
                b = poionts[j][1] - poionts[i][1];
                if (a == 0) continue;
                double k = b / a,
                c = poionts[j][1] - k * poionts[j][0];
                double[] cur = {k, c};
                lines.put(cur, 0);
            }
        }

        for (double[] cur: poionts) {
                for (double[] key: lines.keySet()) {
                    if (key[0] * cur[0] + key[1] == cur[1]) {
                        lines.put(key, lines.get(key) + 1);
                    }
                }
        }

        int res = 1;
        double[] kb = null;
        for (double[] key: lines.keySet()) {
            if (lines.get(key) > res) {
                res = lines.get(key);
                kb = key;
            }
            System.err.println(Arrays.toString(key) + " : " + lines.get(key));
        }
       
        return res;
    }


    @Test
    public void test() {
        double[][] points = {
            {1, 2}, 
            {2, 3}, 
            {2, 4},
            {5, 6}
        };

        maxOnlinePoionts(points);
    }

    public static void main(String[] args) {
        System.out.println(Runtime.getRuntime().availableProcessors());
    }
}
